import { Form, Input, Button } from 'antd';
import request from '../../utils/request';
import { useNavigate } from 'react-router-dom';
function Login() {
    const navigate = useNavigate();
    const handleSubmit = (values) => {
        console.log('Login attempt:', values);
        request('http://10.2.35.4/api/login', {
            method: 'POST',
            data: values,
        }).then(res => {
            if (res.code == 200) {
                // 路由跳转
                console.log('登录成功')
                navigate('/home')
            } else {
                console.log('登录失败')
            }
        })
    };
    return (
        <div className="login-container">
            <h2>Login</h2>
            <Form onFinish={handleSubmit}>
                <Form.Item
                    label="工号"
                    name="jobnumber"
                    rules={[{ required: true, message: 'Please input your jobnumber!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: 'Please input your password!' }]}
                >
                    <Input.Password />
                </Form.Item>
                <Form.Item>
                    <Button type="primary" htmlType="submit">
                        Login
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
}
export default Login;